//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef _SCSI2_H_
#define _SCSI2_H_

//
// S C S I - 2   D E V I C E   T Y P E S
//

#define SCSI_DEVICE_DIRECT_ACCESS       0x00    // e.g. disk
#define SCSI_DEVICE_SEQUENTIAL_ACCESS   0x01
#define SCSI_DEVICE_PRINTER             0x02
#define SCSI_DEVICE_PROCESSOR           0x03
#define SCSI_DEVICE_WRITE_ONCE          0x04
#define SCSI_DEVICE_CDROM               0x05
#define SCSI_DEVICE_SCANNER             0x06
#define SCSI_DEVICE_OPTICAL             0x07
#define SCSI_DEVICE_MEDIUM_CHANGER      0x08
#define SCSI_DEVICE_COMM                0x09
#define SCSI_DEVICE_UNKNOWN             0x1F

//
// S C S I - 2   M E D I U M   T Y P E S
//

#define SCSI_MEDIUM_UNKNOWN             0xFF

//
// C D - R O M   M E D I U M   T Y P E S
//

#define MEDIUM_CD_ROM_UNKNOWN   0x00
#define MEDIUM_CD_ROM_120       0x01
#define MEDIUM_CD_DA_120        0x02
#define MEDIUM_CD_MIXED_120     0x03
#define MEDIUM_CD_HYBRID_120    0x04
#define MEDIUM_CD_ROM_80        0x05
#define MEDIUM_CD_DA_80         0x06
#define MEDIUM_CD_MIXED_80      0x07
#define MEDIUM_CD_HYBRID_80     0x08
#define MEDIUM_CDR_ROM_UNKNOWN  0x10
#define MEDIUM_CDR_ROM_120      0x11
#define MEDIUM_CDR_DA_120       0x12
#define MEDIUM_CDR_MIXED_120    0x13
#define MEDIUM_CDR_HYBRID_120   0x14
#define MEDIUM_CDR_ROM_80       0x15
#define MEDIUM_CDR_DA_80        0x16
#define MEDIUM_CDR_MIXED_80     0x17

//
// M A N D A T O R Y   S C S I - 2   C O M M A N D S
//

#define SCSI_TEST_UNIT_READY    0x00
#define SCSI_REQUEST_SENSE      0x03
#define SCSI_INQUIRY            0x12
#define SCSI_SEND_DIAGNOSTIC    0x1D

//
// M A N D A T O R Y   D E V I C E   S P E C I F I C   C O M M A N D S
//

#define SCSI_READ10               0x28
#define SCSI_READ_CAPACITY        0x25
#define SCSI_READ_FORMAT_CAPACITY 0x23

//
// O P T I O N A L   D E V I C E   S P E C I F I C   C O M M A N D S
//

#define SCSI_MODE_SELECT6       0x15
#define SCSI_MODE_SENSE6        0x1A
#define SCSI_START_STOP         0x1B
#define SCSI_WRITE10            0x2A
#define SCSI_MODE_SELECT10      0x55
#define SCSI_MODE_SENSE10       0x5A

// XP
#define SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
#define SCSI_VERIFY             0x2F

//
// ( A T A P I )   C D - R O M   C O M M A N D S
//

#define SCSI_CD_READ_TOC        0x43
#define SCSI_CD_PLAY10          0x45
#define SCSI_CD_PLAY_MSF        0x47
#define SCSI_CD_PAUSE_RESUME    0x4B
#define SCSI_CD_STOP            0x4E

//
// M O D E  P A G E S
//

#define MODE_PAGE_FLEXIBLE_DISK 0x05
#define MODE_PAGE_CDROM         0x0D
#define MODE_PAGE_CDROM_AUDIO   0x0E
#define MODE_PAGE_CDROM_CAPS    0x2A

//
// S C S I - 2   S E N S E   K E Y S
//

#define SENSE_NONE              0x00
#define SENSE_RECOVERED_ERROR   0x01
#define SENSE_NOT_READY         0x02
#define SENSE_MEDIUM_ERROR      0x03
#define SENSE_HARDWARE_ERROR    0x04
#define SENSE_ILLEGAL_REQUEST   0x05
#define SENSE_UNIT_ATTENTION    0x06
#define SENSE_DATA_PROTECT      0x07
#define SENSE_BLANK_CHECK       0x08

//
// S C S I - 2   A S C
//

#define ASC_LUN                     0x04
#define ASC_INVALID_COMMAND_FIELD   0x24
#define ASC_MEDIA_CHANGED           0x28
#define ASC_RESET                   0x29
#define ASC_COMMANDS_CLEARED        0x2F
#define ASC_MEDIUM_NOT_PRESENT      0x3A

//
// M A X  L U N
//

#define MAX_LUN      0x7

#define SCSI_CDB_6    6
#define SCSI_CDB_10  10
#define UFI_CDB      12
#define ATAPI_CDB    12
#define MAX_CDB      UFI_CDB



#if defined(_INTEL) || defined(_EVC)
#undef DECL_PACKED
#define DECL_PACKED
#pragma pack(push, 1)
#endif
typedef struct _READ_CAPACITY_DATA {
    DWORD LastLogicalBlockAddress;
    DWORD BlockLength;
} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;

typedef struct DECL_PACKED _SENSE_DATA {
    UCHAR ErrorCode:7;
    UCHAR Valid:1;
    UCHAR SegmentNumber;
    UCHAR SenseKey:4;
    UCHAR Reserved:1;
    UCHAR IncorrectLength:1;
    UCHAR EndOfMedia:1;
    UCHAR FileMark:1;
    UCHAR Information[4];
    UCHAR AdditionalSenseLength;
    UCHAR CommandSpecificInformation[4];
    UCHAR AdditionalSenseCode;
    UCHAR AdditionalSenseCodeQualifier;
    UCHAR FieldReplaceableUnitCode;
    UCHAR SenseKeySpecific[3];
} SENSE_DATA, *PSENSE_DATA;

typedef struct DECL_PACKED _STD_INQUIRYDATA {
    UCHAR DeviceType;//bit7-5 Reserved, bit4-0 DeviceType
    UCHAR RemovableMedia;//bit 7: RemovableMedia,bit6-0 Reserved
    UCHAR Reserved2;//BYTE 2
    UCHAR AERC_NACA;//bit7 AERC bit6 Obsolete0 bit5 NACA bit4-0 Reserved
    UCHAR Reserved4[3];//BYTE4 - 6
    UCHAR  Combinated;//bit0 SoftReset bit1 CommandQueue bit2 Reserved
                     //bit3 LinkedCommands bit4 Synchronous
                     //bit5 Wide16Bit bit6 Wide32Bit
                     //bit7 RelativeAddressing
    UCHAR VendorId[8];
    UCHAR ProductId[16];
    UCHAR ProductRevisionLevel[4];
    /* Above is 36 bytes can be tranmitted by Bulk */
//    UINT8 VendorSpecific[20];
//    UINT8 InfoUnitSupport : 1;
//    UINT8 QuickArbitSupport : 1;
//    UINT8 Clocking : 2;
//    UINT8 Reserved6 : 4;
//    UINT8  Reserved7 ;
//    UINT16 VersionDescriptor[8] ;
//    UINT8 Reserved8[22];
} STD_INQUIRYDATA, *PSTD_INQUIRYDATA;

typedef struct DECL_PACKED _UFI_CB {
    BYTE  bOpCode;                // 0
    BYTE  bReserved1:5;           // 1
    BYTE  bLogicalUnitNumber : 3;
    DWORD dwLogicalBlockAddress;  // 2-5
    BYTE  bReserved2;             // 6
    WORD  wTransferLength;        // 7-8
    BYTE  bReserved3[3];          // 9-11
} UFI_CB, *PUFI_CB;
#if defined(_INTEL) || defined(_EVC)
#pragma pack(pop)
#endif


#endif // _SCSI2_H_

